

const App = getApp();

//网络请求封装
import Request_post from "../../../request/Request_post"
import Request_get from "../../../request/Request_get"
// import Request_post_token from "../../../../request/Request_post_token"
// import Request_get_token from "../../../request/Request_get_token"

import config from '../../../config/config'; 

// 获取当前日期时间：yyyy-mm-dd hh:mm:ss
var todayDatetTime = require("../../../utils/CustomFunction/getNowDateTime.js")

// 将标准日期格式（字符串）转换为时间戳(秒)
var timeTostamp = require("../../../utils/CustomFunction/timeTostamp.js")

// 获取今天的日期：yyyy-mm-dd
var getToday = require("../../../utils/CustomFunction/getToday.js")

//格式化为日期格式 
var formatDate = require("../../../utils/CustomFunction/dateFormat.js")
//反格式化日期格式为字符串 
var unformatDate = require("../../../utils/CustomFunction/dateUnFormat.js")

// 排序
let sorting  = require("../../../utils/CustomFunction/objArr_sort")

//条码、二维码生成
const wxbarcode = require("../../../lib/wxbarcode/index.js")

// import imgs from './img'


Page({
  data: {

		overlay_show: false,
		qrcode_show: false,
		playflg: true,
		default_rafprzImg:  "/SubpkgGame/image/default_rafprzImg.png",
		/** 自定义指针 */
		buttons: [{
      radius: '25%',
      fonts: [{ text: '开始\n抽奖', fontColor: '#fff', top: '-50%', fontSize: '16px' }],
      imgs: [{ src: "http://m.qpic.cn/psc?/V54d7L0P1LZ7zV11UKxu3uQ0OP3KVWF3/bqQfVz5yrrGYSXMvKr.cqSVxUoVMD.Wi79CRgkHQxn1z3Wy9i0TJqJCsMYgn0fRwwS2cFCbQwY8tMF8r60t26ggsqk3lDvHjsQLPiyV6lWw!/b&bo=.gAIAQAAAAADF8E!&rf=viewer_4", width: '120%', top: '-135%' }]
		}],
		/** 转盘样式 */
    blocks: [
			//正式环境用的转盘
			{ imgs: [{ src: "http://m.qpic.cn/psc?/V54d7L0P1LZ7zV11UKxu3uQ0OP3KVWF3/bqQfVz5yrrGYSXMvKr.cqT1raqRJ8j2MggCwUNqk56DUwsOOpDqnXnpcEisqYHHxcV8OlNH1BzTXZh3bOwmohhoDsU8Pazuz4.L.MHS7YS0!/b&bo=9AH0AQAAAAADByI!&rf=viewer_4", width: '100%', rotate: true }] },
			//测试用的美女转盘
			// { imgs: [{ src: "http://m.qpic.cn/psc?/V54d7L0P1LZ7zV11UKxu3uQ0OP3KVWF3/bqQfVz5yrrGYSXMvKr.cqeamGQ7TaUEaymQ*Z.Wf*Os5tMhBCRAGdgpbj0llbCgnQ4FQTWBOaz2UZyMB4NT5.bnIgfAZLcfftOYRmdx.mGY!/b&bo=OAQ4BAAAAAADByI!&rf=viewer_4", width: '100%', rotate: true }] },
		],
		/** 一次性活动的奖品图片（后台没有设置奖品图片，只能用这个来匹配） */
		rafprz_image:[
			{
				rafprzdes: "智能电饭煲",
				rafprzid: "01",
				img: "https://crm.hexieshoppingmall.com/imgfile/upgrade/img/20231103.png"
			},
			{
				rafprzdes: "小天鹅洗衣机",
				rafprzid: "02",
				img: "https://crm.hexieshoppingmall.com/imgfile/upgrade/img/20231101.png"
			},
			{
				rafprzdes: "智能扫地机",
				rafprzid: "03",
				img: "https://crm.hexieshoppingmall.com/imgfile/upgrade/img/20231102.png"
			}
		]

	},
		
	onLoad:function(options){
		var that = this
	
		// 商场用的页面背景图
		that.setData({ TitlePic: 'http://m.qpic.cn/psc?/V54d7L0P1LZ7zV11UKxu3uQ0OP3KVWF3/bqQfVz5yrrGYSXMvKr.cqZRYhopvSxXEMMZrwL4qYCoLl1yobBEgIPfuQcae8C6or0GDzP*gMQVjVlf5dmyrrymKqCYdCD3SVXLxl7pb0pY!/b&bo=7gKPBgAAAAABB0U!&rf=viewer_4' })

		// 本机的高度
		var localmchHeight = App.globalData.localmchHeight * 2
		that.setData({
			localmchHeight
		})

		// 获取现在的日期时间(时间戳)
		const getnowDateTime = todayDatetTime.getNowDateTime()
		const todaytime = timeTostamp.timeTostamp(getnowDateTime)
		that.setData({
			todaytime
		})

	},


	/** 列表的遮罩显示 */
	onClickShow() {
    this.setData({ overlay_show: true });
  },
  onClickHide() {
    this.setData({ overlay_show: false });
	},
	

	/** 二维码的遮罩显示 */
	onQrcodeClickShow() {
    this.setData({ qrcode_show: true });
  },
  onQrcodeClickHide() {
		this.myrafrcdList();	// 关闭核销二维码后，需要重新请求列表，同步已核销状态
    this.setData({ qrcode_show: false });
	},
	

	/** 活动倒计时结束后 */
	count_down_finish(){
		this.onShow();
	},





	/** 001-会员花积分活动规则查询 */
	findmbritgruluse(actno){
		var that = this
		// that.getItgrulusePromise = new Promise((resolve, reject)=>{
			var todaytime = that.data.todaytime
			Request_get.get(
				config.domainName+"/api_wxmkt_server/mbritguse/findmbritgruluse",
				{
					mbl: wx.getStorageSync('StrMbrInfo').mbl,
					useitgactid: actno,  // 花积分活动ID，必填
				},
				function(res){
					if( res && res.return_no == 1){
						var itgruluseArray = res.return_data
						var obj = {}
						var vldrul = false
						for(var i in itgruluseArray){
							itgruluseArray[i].bdtm = timeTostamp.timeTostamp(formatDate.DateFormat(itgruluseArray[i].enldat))
							itgruluseArray[i].edtm = timeTostamp.timeTostamp(formatDate.DateFormat(itgruluseArray[i].disdat))
							if(itgruluseArray[i].bdtm <= todaytime && itgruluseArray[i].edtm >= todaytime){
								that.setData({
									itgruluseInfo: itgruluseArray[i]
								})
								vldrul = true
								break;
							}
						}
						if(!vldrul){
							wx.showModal({
								title: '未设置游戏启动规则，',
								showCancel: false,
								confirmText:"确定",
							})
						}
					}
				}
			)
		// })
	},
	/** 003-获取会员抽奖活动详情 */
	rafActInfo(){
		var that = this
		// that.getActInfoPromise = new Promise((resolve, reject)=>{
			Request_get.get(
				config.domainName+"/api_wxmkt_server/mbritguse/rafActInfo",
				{},
				function(res){
					if( res && res.return_no == 1){
						var temprafactinfo = res.return_data
						console.log(temprafactinfo)
						// 现在的日期、时间 
						var nowdatetime_tamp = timeTostamp.timeTostamp(formatDate.DateFormat(todayDatetTime.getNowDateTime()))
						// 获取今天的活动日期时间 (今天的yyyddmm +  活动详情的enltim 和 distim)
						const act_today_bdtm_tamp = timeTostamp.timeTostamp(formatDate.DateFormat(unformatDate.DatString(getToday.getToday()) + temprafactinfo.enltim))
						const act_today_edtm_tamp = timeTostamp.timeTostamp(formatDate.DateFormat(unformatDate.DatString(getToday.getToday()) + temprafactinfo.distim))

						if(temprafactinfo.stsid == '03'){		// 01-未发布，02-未激活，03-已激活
							if(nowdatetime_tamp >= act_today_bdtm_tamp && nowdatetime_tamp <= act_today_edtm_tamp){						// 现在是活动日
								that.setData({
									rafActInfo: res.return_data,
									prizes_res: res.return_data.rafprzconf,
									time: (act_today_edtm_tamp - nowdatetime_tamp) * 1000
								})
								// 获取活动详情后，查询：001-会员花积分活动规则查询
								that.findmbritgruluse("01");  // 01-大转盘活动
		
								// 构建转盘所需的奖品数组
								var prizes = [] // 实际转盘的奖品数组
								var prizes_res = that.data.prizes_res // 后台设置的奖品数组的请求回调
								for(var i in prizes_res){
									var Obj = {}
									Obj.name = prizes_res[i].rafprzdes
									Obj.fonts = [{text:prizes_res[i].rafprzdes,top:'80rpx',fontColor:'black',fontSize:'26rpx',fontWeight:'',lineHeight:'',wordWrap:'',lengthLimit:'90%',lineClamp:1}]
									Obj.imgs = [{src: that.data.default_rafprzImg ,top:'135rpx',width:'64rpx',height:'64rpx'}]
									Obj.rafprzdes = prizes_res[i].rafprzdes
									Obj.rafprzid = prizes_res[i].rafprzid
									Obj.rafprzpolsiz = prizes_res[i].rafprzpolsiz
									Obj.rafprzqty = prizes_res[i].rafprzqty
									Obj.rafprztypid = prizes_res[i].rafprztypid
									Obj.sum_rafprzpolsiz = prizes_res[i].sum_rafprzpolsiz
									
									prizes.push(Obj)
								}
								
								//在奖品列表的第2个奖品后，添加“谢谢参与”奖项
								prizes.splice(2,0,{ name: '谢谢参与',
									fonts:[{text:'谢谢参与',top:'80rpx',fontColor:'black',fontSize:'26rpx',fontWeight:'',lineHeight:'',wordWrap:'',lengthLimit:'90%',lineClamp:1}],
									imgs:[{src:'http://m.qpic.cn/psc?/V54d7L0P1LZ7zV11UKxu3uQ0OP3KVWF3/bqQfVz5yrrGYSXMvKr.cqXNpT.lnWRaDb7rrRFAZ6WgJ04O4QzOxcdGfvQb4cXqOf82VjkitEw6MvQAzDLPRIqYxol2ezowlzkH9dIXgfy0!/b&bo=AAEAAQAAAAADByI!&rf=viewer_4',top:'135rpx',width:'64rpx',height:'64rpx'}]
								},) 
								//在奖品列表的第5个奖品后，添加“谢谢参与”奖项
								prizes.splice(5,0,{ name: '谢谢参与',
									fonts:[{text:'谢谢参与',top:'80rpx',fontColor:'black',fontSize:'26rpx',fontWeight:'',lineHeight:'',wordWrap:'',lengthLimit:'90%',lineClamp:1}],
									imgs:[{src:'http://m.qpic.cn/psc?/V54d7L0P1LZ7zV11UKxu3uQ0OP3KVWF3/bqQfVz5yrrGYSXMvKr.cqXNpT.lnWRaDb7rrRFAZ6WgJ04O4QzOxcdGfvQb4cXqOf82VjkitEw6MvQAzDLPRIqYxol2ezowlzkH9dIXgfy0!/b&bo=AAEAAQAAAAADByI!&rf=viewer_4',top:'135rpx',width:'64rpx',height:'64rpx'}]
								},) 
								//在奖品列表的第1个奖品后，添加“谢谢参与”奖项
								prizes.splice(1,0,{ name: '谢谢参与',
									fonts:[{text:'谢谢参与',top:'80rpx',fontColor:'black',fontSize:'26rpx',fontWeight:'',lineHeight:'',wordWrap:'',lengthLimit:'90%',lineClamp:1}],
									imgs:[{src:'http://m.qpic.cn/psc?/V54d7L0P1LZ7zV11UKxu3uQ0OP3KVWF3/bqQfVz5yrrGYSXMvKr.cqXNpT.lnWRaDb7rrRFAZ6WgJ04O4QzOxcdGfvQb4cXqOf82VjkitEw6MvQAzDLPRIqYxol2ezowlzkH9dIXgfy0!/b&bo=AAEAAQAAAAADByI!&rf=viewer_4',top:'135rpx',width:'64rpx',height:'64rpx'}]
								},) 
								console.log(prizes)
		
								
								// 由于后台不能录入奖品图片，所以这里更换奖品图片：(参见： data:{ rafprz_image:[....] } ）
								var rafprz_image = that.data.rafprz_image
								for(var i in prizes){
									for(var e in prizes[i].imgs){
										for(var k in rafprz_image){
											if(prizes[i].name == rafprz_image[k].rafprzdes){
												prizes[i].imgs[e].src = rafprz_image[k].img
											}
										}
									}
								}
								
								that.setData({
									prizes,
									actstsflg: '01'			// 活动失效性：01-生效中；02-将来生效；99-活动未生效
								})
								// resolve(true)

							}else if(nowdatetime_tamp < act_today_bdtm_tamp){																					// 活动即将开始
								that.setData({
									rafActInfo: res.return_data,
									prizes_res: res.return_data.rafprzconf,
									time: (act_today_bdtm_tamp - nowdatetime_tamp) * 1000
								})
								console.log(that.data.rafActInfo)
								// 获取活动详情后，查询：001-会员花积分活动规则查询
								that.findmbritgruluse("01");  // 01-大转盘活动
		
								// 构建转盘所需的奖品数组
								var prizes = [] // 实际转盘的奖品数组
								var prizes_res = that.data.prizes_res // 后台设置的奖品数组的请求回调
								for(var i in prizes_res){
									var Obj = {}
									Obj.name = prizes_res[i].rafprzdes
									Obj.fonts = [{text:prizes_res[i].rafprzdes,top:'80rpx',fontColor:'black',fontSize:'26rpx',fontWeight:'',lineHeight:'',wordWrap:'',lengthLimit:'90%',lineClamp:1}]
									Obj.imgs = [{src:'',top:'135rpx',width:'64rpx',height:'64rpx'}]
									Obj.rafprzdes = prizes_res[i].rafprzdes
									Obj.rafprzid = prizes_res[i].rafprzid
									Obj.rafprzpolsiz = prizes_res[i].rafprzpolsiz
									Obj.rafprzqty = prizes_res[i].rafprzqty
									Obj.rafprztypid = prizes_res[i].rafprztypid
									Obj.sum_rafprzpolsiz = prizes_res[i].sum_rafprzpolsiz
									
									prizes.push(Obj)
								}
								//在奖品列表的第2个奖品后，添加“谢谢参与”奖项
								prizes.splice(2,0,{ name: '谢谢参与',
									fonts:[{text:'谢谢参与',top:'80rpx',fontColor:'black',fontSize:'26rpx',fontWeight:'',lineHeight:'',wordWrap:'',lengthLimit:'90%',lineClamp:1}],
									imgs:[{src:'http://m.qpic.cn/psc?/V54d7L0P1LZ7zV11UKxu3uQ0OP3KVWF3/bqQfVz5yrrGYSXMvKr.cqXNpT.lnWRaDb7rrRFAZ6WgJ04O4QzOxcdGfvQb4cXqOf82VjkitEw6MvQAzDLPRIqYxol2ezowlzkH9dIXgfy0!/b&bo=AAEAAQAAAAADByI!&rf=viewer_4',top:'135rpx',width:'64rpx',height:'64rpx'}]
								},) 
								//在奖品列表的第5个奖品后，添加“谢谢参与”奖项
								prizes.splice(5,0,{ name: '谢谢参与',
									fonts:[{text:'谢谢参与',top:'80rpx',fontColor:'black',fontSize:'26rpx',fontWeight:'',lineHeight:'',wordWrap:'',lengthLimit:'90%',lineClamp:1}],
									imgs:[{src:'http://m.qpic.cn/psc?/V54d7L0P1LZ7zV11UKxu3uQ0OP3KVWF3/bqQfVz5yrrGYSXMvKr.cqXNpT.lnWRaDb7rrRFAZ6WgJ04O4QzOxcdGfvQb4cXqOf82VjkitEw6MvQAzDLPRIqYxol2ezowlzkH9dIXgfy0!/b&bo=AAEAAQAAAAADByI!&rf=viewer_4',top:'135rpx',width:'64rpx',height:'64rpx'}]
								},) 
		
								// 设置奖品图片：(参见： data:{ rafprz_image:[....] } ）
								var rafprz_image = that.data.rafprz_image
								for(var i in prizes){
									for(var e in prizes[i].imgs){
										for(var k in rafprz_image){
											if(prizes[i].name == rafprz_image[k].rafprzdes){
												prizes[i].imgs[e].src = rafprz_image[k].img 
											}
										}
									}
								}
								that.setData({
									prizes,
									actstsflg: '02'			// 活动失效性：01-生效中；02-将来生效；99-活动未生效
								})
								// resolve(true)
							}else if(nowdatetime_tamp > act_today_edtm_tamp){																																							// 活动已过期
								that.setData({
									actstsflg: '99'			// 活动失效性：01-生效中；02-即将生效；99-活动未生效
								})
							}
						}else{
							that.setData({
								actstsflg: '99'			// 活动失效性：01-生效中；99-活动未生效
							})
						}
						// console.log(that.data.actstsflg)
					}
				}
			)
		// })

	},
	/** 004-会员抽奖（获取抽奖结果） */
	doRaffle(){
		var that = this
		const getnowDateTime = todayDatetTime.getNowDateTime()
		const optdat = unformatDate.DatString(getnowDateTime)
		const srcbllno = wx.getStorageSync('StrMbrInfo').mbrid +  + Math.round(new Date() / 1000)
		const useitg = that.data.itgruluseInfo.itgvlu
		var prizes = that.data.prizes
		var actstsflg = that.data.actstsflg

		// 花积分规则未获取成功
		if(!useitg){
			wx.showModal({ 
				content: '未获取到抽奖规则，请刷新页面重试',
				showCancel: false,
				confirmText:"确定",
			})
			return;
		}
		if(!prizes || !actstsflg){
			wx.showModal({ 
				content: '未获取到抽奖活动详情，请刷新页面重试',
				showCancel: false,
				confirmText:"确定",
			})
			return;
		}

		/** 获取中奖结果 */
		that.DrawResultsPromise = new Promise((resolve, reject)=>{
			wx.request({
				url: config.domainName+"/api_wxmkt_server/mbritguse/doRaffle",
				data:{
					appid: config.as_appid,
					appuserid: App.globalData.wx_openid,
					unionid: App.globalData.unionid,
					mbl: wx.getStorageSync('StrMbrInfo').mbl,
					oprcltid: config.cltid,
					oprid: "01",				// 花积分规则id ：01-大转盘游戏
					oprdat: optdat,     
					srcbllno: srcbllno,
					useitgvlu: parseInt(useitg),    
					brief: ""
				},
				method:"POST",
				header: {'content-type': 'application/json'}, // 默认值
				success (res) {
					if(res.data.sc == 200){
						var winningInfo = res.data.payload.return_data			// 中奖结果
						console.log('请求了中奖结果',winningInfo)
						if(winningInfo.rafflg == 'y'){
							console.log(prizes)
							for(var i in prizes){
								console.log(prizes[i])
								if(prizes[i].rafprzid == winningInfo.rafprzid){
									that.setData({
										winning_prizes_index: i,
										winning_prizes_rafprzdes:prizes[i].rafprzdes,
										winning_rafflg: winningInfo.rafflg
									})
									resolve(true)
									console.log('获奖结果已拿到：已中奖 + 中奖索引')
									break;
								}
							}
						}else{
							that.setData({
								winning_rafflg: winningInfo.rafflg
							})
							resolve(true)
							console.log('获奖结果已拿到：未中奖')
						}
					}else{
						wx.showModal({
							title: `${res.data.st}`,
			        showCancel: false,   //是否显示取消按钮
			        confirmText:"确认",    //默认是“确定”
			        success: function (res) {
			          if (res.confirm) {    //点击确认
			            wx.redirectTo({
										url: App.globalData.homePage,
									})
			          }
			        },
			      })
					}

				}
			})
		})

	},

	/** 开始转转盘的方法 new*/ 
	wheelStart () {
		var that = this

		// 距离游戏结束小于30秒时就不允许玩了  1分钟时间戳：60000
		var rafActInfo = that.data.rafActInfo
		// 现在的日期、时间 
		var nowdatetime_tamp = timeTostamp.timeTostamp(formatDate.DateFormat(todayDatetTime.getNowDateTime()))
		// 获取今天的活动日期时间 (今天的yyyddmm +  活动详情的enltim 和 distim)
		const act_today_bdtm_tamp = timeTostamp.timeTostamp(formatDate.DateFormat(unformatDate.DatString(getToday.getToday()) + rafActInfo.enltim))
		const act_today_edtm_tamp = timeTostamp.timeTostamp(formatDate.DateFormat(unformatDate.DatString(getToday.getToday()) + rafActInfo.distim))

		if(( act_today_edtm_tamp - nowdatetime_tamp ) < 30){
			wx.showModal({ 
				title: '操作提示',
				content: '抱歉，现在距离本轮游戏活动的截至时间已经小于30秒。系统设置已不可再进行游戏。谢谢您对我们的支持！',
				showCancel: false,
				confirmText:"确定",
			})
			return;
		}

		// 积分不够不给玩盘盘
		var nowvlditg = that.data.vlditgvlu || 0
		var gameuseitg = that.data.itgruluseInfo.itgvlu
		if( nowvlditg < gameuseitg ){
			wx.showModal({
				title: '游戏提示',
				content: '抱歉，您的积分尚不够一次游戏所需的积分值',
				showCancel: false,
				confirmText:"确定",
			})
			return;
		}
		
		// 判断活动是否有效，有效活动才开始转转盘
		var actstsflg = that.data.actstsflg
		if(actstsflg !== '01'){
			wx.showToast({
				title: '当前暂无活动进行',
				duration:2000,
				mask:true,
				icon:'none',
			})
			return
		}

		// 防止重复点击大转盘
		var playflg = that.data.playflg
		if(!playflg){
			wx.showToast({
				title: '请等待本轮转盘游戏结束，再点击',
				duration:2000,
				mask:true,
				icon:'none',
			})
			return
		}else if(playflg){
			
				wx.showModal({
					content: `是否使用${gameuseitg}积分进行一次幸运大转盘抽奖游戏？`,
					showCancel:true,
					confirmText:"确认",
					cancelText:"再想想",
					success: function (res) {
						if (res.confirm) {
							// console.log('转盘开始事件')
							that.setData({playflg: false})
							// *******测试用*******
							that.setData({
								winning_rafflg:""
							})
							// 获取抽奖结果（积分已使用）
							that.doRaffle();

							that.DrawResultsPromise.then(v => {
								// 获取抽奖组件实例
								const child = that.selectComponent('#lucky-wheel')
								// 调用play方法开始旋转
								child.play()
								// 用定时器设置转盘的转动时间
								setTimeout(() => {
									// 3.5s 后得到中奖信息（是否中奖 + 中奖后的中奖索引）
									var winning_rafflg = that.data.winning_rafflg
									var winning_prizes_index = that.data.winning_prizes_index
									if(winning_rafflg){
										var arr = [1,3,5] // 未中奖的数组下标，构成一个数组
										var randomindex =  Math.floor(Math.random() * arr.length + 1)-1   // 如果没中奖，则谢谢参与（未中奖数组: arr），将随机出一个,注意：这里是数组的下标
										var index = winning_rafflg == 'y'? winning_prizes_index:arr[randomindex];
										// console.log('获取到的中奖索引',index)
										// 调用stop方法然后缓慢停止
										child.stop(index)
									}else{
										wx.showModal({
											content: `网络通讯失败，游戏已中断`,
							        showCancel: false, 
							        confirmText:"确认", 
							        success: function (res) {
							          if (res.confirm) { 
								          child.init()
							          }
							        },
							      })
									}
								}, 3500)	
							})
						}else{
							return;
						}
					},
				})
			
		}
		

/********************************* 分割一下 ************************************ */

// 		/** 组件原始代码 */
// 		// 获取抽奖组件实例
// 		const child = this.selectComponent('#lucky-wheel')
// 		// 调用play方法开始旋转
// 		child.play()
// 		// 用定时器模拟请求接口
// 		setTimeout(() => {

// 			wx.showModal({
// 				content: `网络通讯失败，游戏已中断，您此次游戏的积分并不会被扣减.`,
//         showCancel: false, 
//         confirmText:"确认", 
//         success: function (res) {
//           if (res.confirm) { 
// 	          child.init()
//           }
//         },
//       })
		
// 			// 3s 后得到中奖索引
// 			const index = Math.random() * 8 >> 0
// 			// 调用stop方法然后缓慢停止
// 			// child.stop(index)
// 			// child.stop(6)

// 		}, 3000)	


	},
	
	
	
	
	
	
	wheelEnd (event) {
		var that = this
		var winning_rafflg = that.data.winning_rafflg
		if(winning_rafflg == 'y'){
			// 中奖奖品详情
			wx.showModal({
				title: '中奖提示',
				content: '恭喜你获得: ' + event.detail.name,
				success (res) {
					that.setData({playflg: true})
				}
			})
		}else if(winning_rafflg == 'n'){
			// 中奖奖品详情
			wx.showModal({
				title: '有点小遗憾',
				content: `本次没有抽中奖品，请再接再厉哦！`,
				success (res) {
					that.setData({playflg: true})
				}
			})
		}

		// 转盘结束后，刷新会员的积分、账户等信息
		that.onShow();
    
	},


	/** 查看我的中奖记录 */
	myrafrcdList(){
		var that = this
		var playflg = this.data.playflg
		if(!playflg){
			wx.showToast({
				title: '请等待本轮转盘游戏结束!',
				duration:2000,
				mask:true,
				icon:'none',
			})
			return
		}
		that.onClickShow();
		Request_get.get(
			config.domainName+"/api_wxmkt_server/mbritguse/rafrcdList",
			{
				mbrid: wx.getStorageSync('StrMbrInfo').mbrid
			},
			function(res){
				if(res && res.return_no == 1){
					const rafrcdlist = res.return_data.filter((item, index, arr) => item.rafflg == 'y')
					rafrcdlist.sort(sorting.compareValues('rafdtm','desc'));
					that.setData({
						rafrcdlist
					})
					console.log(that.data.rafrcdlist)
				}
			}
		)
	},

	buildRafrcdQrCode(e){
		var that = this
		console.log(e)
		that.onQrcodeClickShow()
		var id = e.currentTarget.dataset.id
		Request_get.get(
			config.domainName+"/api_wxmkt_server/mbritguse/buildRafrcdQrCode",
			{
				id:id
			},
			function(res){
				console.log(res)
				if(res && res.return_no == 1){
					wxbarcode.qrcode('qrcode',res.return_data.qrcode,400,400);
				}
			}
		)

	},

	onShow(){
		
		this.getMbrAct();
		this.getMbrItg();
		this.rafActInfo();
		
	},


	onReady () {

	},


	/** 获取会员账户余额查询 */
	getMbrAct:function(){
		var that = this
		Request_get.get(
			config.domainName+"/api_wxmkt_server/mbrbsc/findmbremy",
			{
				mbrl: wx.getStorageSync('StrMbrInfo').mbl
			},
			function(res){
				// console.log(res.return_data)
				var actInfo = res.return_data
				var mbrAccInfo = []
				var obj = {}
				obj.accdes = '电子币账户'
				obj.vldaccamt = actInfo.emysumamt
				mbrAccInfo.push(obj)
				var obj = {}
				obj.accdes = '电子券账户'
				obj.vldaccamt = actInfo.crtsumamt
				mbrAccInfo.push(obj)
				
				that.setData({
					mbrAccInfo
				})
			}
		)
	},

  /** 获取会员有效积分余额查询 */
	getMbrItg:function(){
		var that = this
		Request_get.get(
			config.domainName+"/api_wxmkt_server/mbrreg/findwxmbrbymbl",
			{
				mbl: wx.getStorageSync('StrMbrInfo').mbl
			},
			function(res){
				// console.log('积分余额：',res.return_data.vlditgvlu)
				if(res != 'undefined' && res.return_no == 1){
					that.setData({vlditgvlu: res.return_data.vlditgvlu})
				}
			}
		)
  },
	





})